package com.herui.iot.ui.main;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.herui.sdyu_lib.base.BaseFragment;
import com.herui.sdyu_lib.utils.ToastUtil;
import com.herui.sport_care.R;
import com.herui.sport_care.data.user.UserInfo;
import com.herui.sport_care.ui.BaseSportFragment;
import com.herui.sport_care.ui.mime.LoginActivity;
import com.herui.sport_care.ui.mime.UserChangePasswordActivity;
import com.herui.sport_care.ui.mime.UserChangePhoneActivity;
import com.herui.sport_care.ui.mime.UserPresenter;

import butterknife.BindView;
import butterknife.OnClick;


/**
 * Created by amanda.shan on 2022/10/19.
 */
public class MimeFragment extends BaseSportFragment {

    @BindView(R.id.tv_name)
    TextView tv_name;
    @BindView(R.id.tv_organ_name)
    TextView tv_organ_name;

    UserPresenter userPresenter;


    public static MimeFragment newInstance() {
        MimeFragment fragment = new MimeFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    public MimeFragment() {
        userPresenter = new UserPresenter(new UserPresenter.UserView() {
            @Override
            public void onLoginOut() {
                ToastUtil.showMessage("登出成功");
                baseActivity.jump(LoginActivity.class);
                baseActivity.finish();
            }
        });
    }

    @Override
    public int getLayout() {
        return R.layout.fragment_mime;
    }

    @Override
    public void initParam() {
    }

    @Override
    public void onResume() {
        super.onResume();

        UserInfo userInfo = userPresenter.getUserInfo();
        tv_name.setText(userInfo.getName());
        tv_organ_name.setText(userInfo.getOrganName()+"");
    }

    @OnClick({R.id.view_change_phone, R.id.view_change_password, R.id.tv_login_out})
    public void onViewClick(View view) {
        switch (view.getId()) {
            case R.id.view_change_phone:
                baseActivity.jump(UserChangePhoneActivity.class);
                break;
            case R.id.view_change_password:
                baseActivity.jump(UserChangePasswordActivity.class);
                break;
            case R.id.tv_login_out:
                userPresenter.loginOut();
                break;
            default:
                break;
        }
    }
}
